<template>
	<div v-cloak class="aui-wrapper aui-page__iframe">
		<div class="aui-content__wrapper">
			<div class="aui-content">
				<el-card shadow="never" class="aui-card--fill">
					<div class="mod-sys__menu">
						<el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
							<el-form-item>
								<el-input v-model="dataForm.code" size="small" placeholder="代码" clearable></el-input>
							</el-form-item>
							<el-form-item>
								<el-input v-model="dataForm.codename" size="small" placeholder="代码名称" clearable></el-input>
							</el-form-item>
							<el-form-item>
								<el-button size="small" @click="getDataList()">查询</el-button>
							</el-form-item>
							<el-form-item>
								<el-button type="primary" size="small" @click="addOrUpdateHandle()"
									v-if="hasPermission('lswms:code:save')">新增</el-button>
							</el-form-item>
							<el-form-item>
								<el-button type="danger" size="small" @click="deleteHandle()"
									v-if="hasPermission('lswms:code:delete')">删除</el-button>
							</el-form-item>
							<!-- <el-form-item>
                                                                <el-button type="info" @click="exportHandle()">导出</el-button>
                                                        </el-form-item> -->
						</el-form>
						<el-table v-loading="dataListLoading" :data="dataList" border
							@selection-change="dataListSelectionChangeHandle" @sort-change="dataListSortChangeHandle"
							style="width: 100%;">
							<el-table-column type="selection" header-align="center" align="center" width="50">
							</el-table-column>
							<el-table-column prop="code" label="代码" sortable="custom" header-align="center"
								align="center"></el-table-column>
							<el-table-column prop="codename" label="代码名称" header-align="center" align="center">
							</el-table-column>

							<el-table-column label='操作' fixed="right" header-align="center" align="center" width="150">
								<template #default="scope">
									<el-button type="text" size="small" @click="addOrUpdateHandle(scope.row.id)"
										v-if="hasPermission('lswms:code:update')">修改
									</el-button>
									<el-button type="text" size="small" @click="deleteHandle(scope.row.code)"
										v-if="hasPermission('lswms:code:delete')">删除
									</el-button>
									<el-button type="text" size="small"
										@click="listHandle(scope.row.id,scope.row.code)"> 明细</el-button>
								</template>
							</el-table-column>
						</el-table>
						<el-pagination :current-page="page" :page-sizes="[10, 20, 50, 100]" :page-size="limit"
							:total="total" layout="total, sizes, prev, pager, next, jumper"
							@size-change="pageSizeChangeHandle" @current-change="pageCurrentChangeHandle">
						</el-pagination>
						<!-- 弹窗, 新增 / 修改 -->
						<CodeAddOrUpdate v-if="addOrUpdateVisible" ref="addOrUpdate" @refresh-data-list="getDataList">
						</CodeAddOrUpdate>
						<!-- 明细界面 -->
						<Codelist v-if="codelistVisible" ref="codelistvue"></Codelist>
					</div>
				</el-card>
			</div>
		</div>
	</div>
</template>

<script>
	import DataList from "@/utils/DataList";
	import {
		ref,
		reactive,
		onMounted,
		nextTick
	} from 'vue';
	import CodeAddOrUpdate from "@/components/lswms/base/CodeAddOrUpdate";
	import Codelist from "@/components/lswms/base/Codelist"
	import {
		hasPermission
	} from "@/utils/hasPermission"
	export default {
		name: "Code",

		components: {
			CodeAddOrUpdate,
			Codelist
		},

		setup() {
			const {
				dataForm,
				mixinViewModuleOptions,
				getDataList,
				dataList,
				total,
				page,
				limit,
				dataListLoading,
				dataListSelectionChangeHandle,
				dataListSortChangeHandle,
				pageSizeChangeHandle,
				pageCurrentChangeHandle,
				addOrUpdateHandle,
				deleteHandle,
				exportHandle,
				addOrUpdateVisible,
				dataListSelections,
				addOrUpdate
			} = DataList();

			onMounted(() => {
				mixinViewModuleOptions.value.getDataListIsPage = true;
				mixinViewModuleOptions.value.getDataListURL = '/lswms/code/page';
				mixinViewModuleOptions.value.deleteURL = '/lswms/code';
				mixinViewModuleOptions.value.deleteIsBatchKey = 'code';
				mixinViewModuleOptions.value.deleteIsBatch = true
				if (mixinViewModuleOptions.value.activatedIsNeed) {
					getDataList();
				}

			})

			const codelistVisible = ref(false);
			const codelistvue = ref(null);

			//打开codelist页
			const listHandle = (id, code) => {
				codelistVisible.value = true;
				nextTick(function() {
					//codelistvue.value.dataForm.id = id;
					codelistvue.value.dataForm.code = code;
					codelistvue.value.init();
				})
			}
			return {
				dataForm,
				mixinViewModuleOptions,
				getDataList,
				dataList,
				total,
				page,
				limit,
				dataListLoading,
				dataListSelectionChangeHandle,
				dataListSortChangeHandle,
				pageSizeChangeHandle,
				pageCurrentChangeHandle,
				addOrUpdateHandle,
				deleteHandle,
				exportHandle,
				addOrUpdateVisible,
				dataListSelections,
				addOrUpdate,

				codelistVisible,
				listHandle,
				codelistvue
			}
		},
		methods: {
			hasPermission
		}
	}
</script>

<style scoped>

</style>
